from django.core.mail import send_mail
from django.conf import settings
from celery_tasks.celery import app
from LabsApp.settings import EMAIL_VERIFY_URL


# 定义一个发送邮件函数
@app.task(name='send_verify_email')
def send_verify_email(to_email, token):
    # 标题
    subject = '实验楼注册邮箱验证'
    # 发送内容
    html_message = '<p>尊敬的用户您好！</p>' \
                   '<p>感谢您使用实验楼。</p>' \
                   '<p>您的邮箱为：%s。请点击此链接激活您的邮箱：</p>' \
                   '<ｐ><a href="%s?token=%s">%s?token=%s</a></ｐ>' % (to_email, EMAIL_VERIFY_URL, token, EMAIL_VERIFY_URL, token)
    # 进行发送
    result = send_mail(subject, '哈哈哈', settings.EMAIL_FROM, [to_email], fail_silently=False,  html_message=html_message)
    return result
